jQuery(function () {
    var $ = jQuery, // just in case. Make sure it's not an other libaray.
            addYunZhujiForm = $("#add-yunzhuji-form"),
            submitBtn = $("#submitCallOutBtn"),
            nextBtn = $('#addYunZhuji');
//提交按钮点击事件
    submitBtn.click(function () {
        //触发表单提交事件
        //addYunZhujiForm.submit();
    });
    //下一步
    nextBtn.click(function () {
        var bool = validator.form();
        if (bool) {
            $('.addYunZhuJiForm').hide();
            $('.yunZhuJiList').show();
        }
    });
//表单验证板块
    var validator = addYunZhujiForm.validate({
        rules: {
            'type': {
                required: true
            },
            'yunaccount': {
                required: true
            },
            'accesskey': {
                required: true
            },
            'seraetaccesskey': {
                required: true
            },
            'secreatid': {
                required: true
            },
            'secretkey': {
                required: true
            },
            'account': {
                required: true
            },
            'password': {
                required: true
            },
            'ip': {
                required: true
            },
            'group': {
                required: true
            },
            'banben': {
                required: true
            }
        },
        messages: {
            'type': {
                required: '选择您即将添加云主机的服务平台'
            },
            'yunaccount': {
                required: '为您云主机设置一个账号名称'
            },
            'accesskey': {
                required: '请输入平台账户的Access key'
            },
            'seraetaccesskey': {
                required: '请输入平台账户的Sercetaccess key'
            },
            'secreatid': {
                required: '请输入平台账户的secretId'
            },
            'secretkey': {
                required: '请输入平台账户的secretKey'
            },
            'account': {
                required: '请输入账号'
            },
            'password': {
                required: '请输入密码'
            },
            'ip': {
                required: '请输入ip或域名'
            },
            'group': {
                required: '请输入组名'
            },
            'banben': {
                required: '请输入版本'
            }
        },
//        errorContainer: "div.error",
//        errorLabelContainer: $("#call-form div .error"),
//        wrapper: "div",
        errorElement: "div",
        errorPlacement: function (error, element) {                             //错误信息位置设置方法  
            error.appendTo(element.parent());     //这里的element是录入数据的对象  
            //error.appendTo(element); 
        },
        submitHandler: function () {
            //form插件的异步无刷新提交
            var actionUrl = addYunZhujiForm.attr('ction');
            addYunZhujiForm.ajaxSubmit({
                type: 'post',
                url: actionUrl,
                success: function (data) {
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    console.log(XmlHttpRequest);
                    console.log(textStatus);
                    console.log(errorThrown);
                },
                complete: function () {

                }
            });
        }
    });
});